package com.hangwei.paperless.adapter;

import android.support.annotation.Nullable;
import android.widget.CheckBox;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.hangwei.paperless.R;
import com.hangwei.paperless.model.bean.Disposition;
import com.twelve.all.adapter.MyAdapter;
import com.twelve.all.utils.Tools;

import java.util.List;

public class Disposition1Adapter extends MyAdapter<Disposition, BaseViewHolder> {

    public Disposition1Adapter( @Nullable List<Disposition> data) {
        super(R.layout.item_result, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Disposition item) {
        helper.setIsRecyclable(false);
        CheckBox checkbox = helper.getView(R.id.checkbox);
        TextView tvType = helper.getView(R.id.tvType);
        if (item.isChecked){
            checkbox.setChecked(true);
            tvType.setTextColor(mContext.getResources().getColor(R.color.blue1));
        }else {
            checkbox.setChecked(false);
            tvType.setTextColor(mContext.getResources().getColor(R.color.black));
        }
        tvType.setText(Tools.checkedString(item.name));
        helper.itemView.setOnClickListener(v -> {
            item.isChecked = !item.isChecked;
            notifyDataSetChanged();
        });
        checkbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
            item.isChecked = isChecked;
            notifyDataSetChanged();
        });
    }
}
